﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using CRC.Inspecciones.Dominio.Controlador;

namespace CRC.Inspecciones.Presentacion
{
    public partial class UsrListarInspeccionesHECHAS : UserControl
    {
        private ControladorListarInspeccionesPeriodicas CLIP = new ControladorListarInspeccionesPeriodicas();

        public UsrListarInspeccionesHECHAS()
        {
            InitializeComponent();
            ListarInspeccionesPeriodicas();
        }

        private void ListarInspeccionesPeriodicas()
        {
            IList<Object[]> infoInspecciones = null;

            try
            {
                lstInspPeriodicas.Rows.Clear();
                infoInspecciones = CLIP.listarInspecciones_Hechas();
                foreach (Object[] infoInspeccion in infoInspecciones)
                {
                    infoInspeccion[1] = false;
                    lstInspPeriodicas.Rows.Add(infoInspeccion);
                }

            }
            catch (Exception ex)
            {

                MessageBox.Show(
                    ex.Message,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1
                 );
            }
        }

        private void btnCerrar_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void buttonGenerar_Click(object sender, EventArgs e)
        {
                this.folderBrowserDialog1.ShowDialog();
                            if (this.folderBrowserDialog1.SelectedPath.Length > 0)
                            {
                                string ruta = this.folderBrowserDialog1.SelectedPath;
                                foreach (DataGridViewRow row in lstInspPeriodicas.Rows)
                                {
                                    if ((bool)row.Cells["Seleccion"].FormattedValue)
                                    {
                                        //imprimir
                                        CRC_Imprimir.Printing_Form impr = new CRC_Imprimir.Printing_Form();
                                        impr.Show(this);
                                        impr.Imprimir_Inspeccion_Hecha((int)row.Cells["Id_Salon"].Value, ruta,false);
                                       }                                  
                                   }
                                }
           }

        private void buttonGenerar_CRC_Click(object sender, EventArgs e)
            {
                this.folderBrowserDialog1.ShowDialog();
                if (this.folderBrowserDialog1.SelectedPath.Length > 0)
                {
                    string ruta = this.folderBrowserDialog1.SelectedPath;
                    foreach (DataGridViewRow row in lstInspPeriodicas.Rows)
                    {
                        if ((bool)row.Cells["Seleccion"].FormattedValue)
                        {
                            //imprimir
                            CRC_Imprimir.Printing_Form impr = new CRC_Imprimir.Printing_Form();
                            impr.Show(this);
                            impr.Imprimir_Inspeccion_Hecha((int)row.Cells["Id_Salon"].Value, ruta,true);
                        }
                    }
                }
          }
        }
        }    
